package com.ljfiction.book.Dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alipay.sdk.app.PayTask;
import com.google.gson.Gson;

import com.ljfiction.book.MyView.SuperButton;
import com.ljfiction.book.R;
import com.ljfiction.book.activitys.BaseActivity;
import com.ljfiction.book.activitys.LoginActivity;
import com.ljfiction.book.http.HttpManager;
import com.ljfiction.book.http.UserManageBean;
import com.ljfiction.book.pay.PayResult;
import com.ljfiction.book.pay.WeiXin;
import com.ljfiction.book.tools.Constant;
import com.ljfiction.book.tools.EventTool;
import com.ljfiction.book.tools.SettingManager;
import com.ljfiction.book.tools.StringQudaoTool;
import com.ljfiction.book.tools.StringTool;
import com.ljfiction.book.tools.Tool;
import com.lzy.okhttputils.OkHttpUtils;
import com.lzy.okhttputils.callback.StringCallback;
import com.lzy.okhttputils.request.BaseRequest;

import org.json.JSONObject;


import java.util.HashMap;

import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Response;


/**
 * Created by Android on 2017/11/20.
 */

public class PayPursDialog {
    private Dialog mDialog;
    private Listener listener;
    private int isselect = 0;
    private BaseActivity baseActivity;
    private HashMap<String, String> reqMap = new HashMap<String, String>();
    private ViewHolder viewHolder;


    public PayPursDialog(final BaseActivity context) {
        mDialog = new Dialog(context, R.style.ActionSheetDialogStyle);
        View view = LayoutInflater.from(context).inflate(R.layout.pay_purs, null);
        //将布局设置给Dialog
        mDialog.setContentView(view);

        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        layoutParams.width = context.getResources().getDisplayMetrics().widthPixels;
        view.setLayoutParams(layoutParams);
        mDialog.getWindow().setGravity(Gravity.BOTTOM);
        mDialog.getWindow().setWindowAnimations(R.style.AnimBottom);
        mDialog.setCancelable(true);
        this.baseActivity = context;
        viewHolder = new ViewHolder(view);
        viewHolder.zhifubaoPurse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isselect == 0) {
                    isselect = 1;
                    viewHolder.weixinSelect.setImageResource(R.mipmap.purse_noselect);
                    viewHolder.zhifubaoSelect.setImageResource(R.mipmap.purse_select);

                } else {
                    return;
                }
            }
        });
        viewHolder.weixinPurse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isselect == 0) {
                    return;
                } else {
                    isselect = 0;
                    viewHolder.weixinSelect.setImageResource(R.mipmap.purse_select);
                    viewHolder.zhifubaoSelect.setImageResource(R.mipmap.purse_noselect);
                }
            }
        });
        viewHolder.purse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.okClick(isselect);

            }
        });

    }

public void setPayNum(String paynum){
    viewHolder.purseMoney.setText("￥ " + paynum + "元");
}

public void thisdismiss(){
    mDialog.dismiss();
}

    public void setListener(Listener listener) {
        this.listener = listener;
    }

    public void show() {
        if (mDialog != null) {
            mDialog.show();
        }
    }


    public interface Listener {
        public void okClick(int isselect);
    }

    static class ViewHolder {
        @BindView(R.id.purse_money)
        TextView purseMoney;
        @BindView(R.id.weixin_select)
        ImageView weixinSelect;
        @BindView(R.id.weixin_purse)
        RelativeLayout weixinPurse;
        @BindView(R.id.zhifubao_select)
        ImageView zhifubaoSelect;
        @BindView(R.id.zhifubao_purse)
        RelativeLayout zhifubaoPurse;
        @BindView(R.id.purse)
        SuperButton purse;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
